<div id="registerDiv" class="login_wrapper">
    <div id="register" class="animate form login_form">
        <section class="login_content">
            <form action="javascript:void(0);">
                <h1>用户注册</h1>
                <div>
                    <input type="text" v-model="user.userName" class="form-control" placeholder="请输入用户名" required="" />
                </div>
                <div>
                    <input type="email" v-model="user.email" class="form-control" placeholder="请输入邮箱地址" required="" />
                </div>
                <div>
                    <input type="password" v-model="user.password" class="form-control" placeholder="请输入密码" required="" />
                </div>
                <div>
                    <a class="btn btn-default submit" href="javascript:void(0);" @click="register()">立即注册</a>
                </div>

                <div class="clearfix"></div>

                <div class="separator">
                    <p class="change_link">注册好了?
                        <a href="/login" class="to_register"> 返回登录页面 </a>
                    </p>

                    <div class="clearfix"></div>
                    <br />

                    <div>
                        <h1><i class="fa fa-paw"></i> 牛牛考试管理注册!</h1>
                        <p>本登录页面注册后登录管理无法查看有效信息，需管理员分配角色.</p>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<!--写js-->
<script type="text/javascript">
    var registerVue = new Vue({
        el: "#registerDiv",
        data: {
            user: {
                email: "",
                userName: "",
                password: "",
            },
        },
        methods: {
            register: function () {
                var self = this;
                if (self.user.email == "" || self.user.userName == "" || self.user.password == "") {
                    layer.msg("Please input register info", { icon: 0 });
                    return;
                }

                $.ajax({
                    url: "/api/user",
                    type: "post",
                    contentType: "application/json",
                    data: JSON.stringify(self.user),
                    success: function (data) {
                        if (data.status == 200) {
                            location.href = "/login";
                        } else {
                            layer.msg(data.message, { icon: 0 });
                        }
                    },
                    error: function (data) {
                        layer.msg(data.responseText, { icon: 0 });
                    },
                });
            },
        },
    });
</script>